package behavioral_pattern.state_pattern;

public class RestrictedState extends AccountState{
    public RestrictedState(NormalState normalState) {
       this.account = normalState.account;
    }
    public RestrictedState(OverdraftState normalState) {
        this.account = normalState.account;
    }

    @Override
    public void deposit(double amount) {
        account.setBalance(account.getBalance()+amount);
        stateCheck();


    }

    @Override
    public void withDraw(double amount) {
        System.out.println("账户受限，取款失败");
    }

    @Override
    public void computeInterest() {
        System.out.println("正常状态，无须支付利息！");
    }

    @Override
    public void stateCheck() {
        if (account.getBalance()>0){
            account.setState(new NormalState(this));
        }else  if (account.getBalance() > -2000){
            account.setState(new OverdraftState(this));
        }
    }
}